<?PHP
function getWeather(){

	global $xoopsDB, $xoopsModule, $xoopsConfig, $xoopsModuleConfig;
	
		$block = array();	
		$result = $xoopsDB->query( "SELECT code FROM ".$xoopsDB->prefix("weather")." WHERE `default` = 'true' LIMIT 1" ) ;
	if($result){

		if (!isset($GLOBALS['xoopsModuleConfig']) || $GLOBALS['xoopsModule']->getVar('dirname') != "weather") {
		  $modhandler = &xoops_gethandler('module');
		  $module = &$modhandler->getByDirname("weather");
		  $config_handler = &xoops_gethandler('config');
		  $xoopsModuleConfig = &$config_handler->getConfigsByCat(0,$module->getVar('mid')); 
		  $block['block_bg']=$xoopsModuleConfig['block_bg'];
		  $block['block_border']=$xoopsModuleConfig['block_border'];	
    	  $block['font_weight']=$xoopsModuleConfig['font_weight'];	
		  $degrees = $xoopsModuleConfig['measurment'];
		}else {
		  $block['block_bg']=$xoopsModuleConfig['block_bg'];
		  $block['block_border']=$xoopsModuleConfig['block_border'];	
    	  $block['font_weight']=$xoopsModuleConfig['font_weight'];	
  		  $degrees = $xoopsModuleConfig['measurment'];
		}
		
		$myrow = $xoopsDB->fetchArray($result);
		$block['code'] = $myrow['code'];
		$url = "http://xml.weather.yahoo.com/forecastrss?p=".$block['code']."&u=$degrees"; 
		if(file ($url)){
		$lines = file ($url);
		}else{
			return false;
		}
		for($i=0; $i < count($lines); $i++){
			if(ereg('img src', $lines[$i])){//get Image
				$imageLine=$i;
			}		
			if(ereg('Current Conditions:', $lines[$i])){//get current conditions
				$CurrentConditionsText=$i+1;
				break;
			}
		}

		$block['image'] = eregi_replace('<BR />',"",$lines[$imageLine]);		
		$block['current'] = eregi_replace('<BR /><BR />',"",$lines[$CurrentConditionsText]);		
	}else{
		return false;
	}
	


return $block;
	
}
?>